package com.fas.system.service.impl;

import com.fas.common.core.domain.AjaxResult;
import com.fas.system.domain.FasIpqc;
import com.fas.system.mapper.FasIpqcMapper;
import com.fas.system.service.IFasIpqcService;
import com.fas.system.util.OrderldUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 巡检员Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-04-27
 */
@Service
public class FasIpqcServiceImpl implements IFasIpqcService
{
    @Resource
    private FasIpqcMapper fasIpqcMapper;
    @Autowired
    OrderldUtil orderldUtil;
    /**
     * 查询巡检员
     * 
     * @param id 巡检员主键
     * @return 巡检员
     */
    @Override
    public FasIpqc selectFasIpqcById(Long id)
    {
        return fasIpqcMapper.selectFasIpqcById(id);
    }



    public List<FasIpqc> selectFasIpqcList(FasIpqc fasIpqc) {

        return fasIpqcMapper.selectFasIpqcList(fasIpqc);
    }

    /**
     * 查询巡检员列表
     * 
     * @param fasIpqc 巡检员
     * @return 巡检员
     */
//    @Override
//    public List<FasIpqc> selectFasIpqcList(FasIpqc fasIpqc)
//    {
//        return fasIpqcMapper.selectFasIpqcList(fasIpqc);
//    }

    /**
     * 根据任一条件查询巡检员列表
     *
     * @param fasIpqc 巡检员
     * @return 巡检员集合
     */
    @Override
    public List<FasIpqc> selectFasIpqcListByAuto(FasIpqc fasIpqc) {
//        return fasIpqcMapper.selectFasIpqcListByAuto(fasIpqc);
        return null;
    }

    /**
     * 新增巡检员
     * 
     * @param fasIpqc 巡检员
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult insertFasIpqc(FasIpqc fasIpqc)    {
        int count = fasIpqcMapper.existsFasIpqc(fasIpqc);
        if(count >0){
            return AjaxResult.error("巡检员已存在，请勿重复添加!");
        }
        int i = fasIpqcMapper.insertFasIpqc(fasIpqc);
        return AjaxResult.success();
    }

    /**
     * 修改巡检员
     * 
     * @param fasIpqc 巡检员
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateFasIpqc(FasIpqc fasIpqc)
    {
        return fasIpqcMapper.updateFasIpqc(fasIpqc);
    }

    /**
     * 批量删除巡检员
     * 
     * @param ids 需要删除的巡检员主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteFasIpqcByIds(Long[] ids)
    {
        return fasIpqcMapper.deleteFasIpqcByIds(ids);
    }

    /**
     * 删除巡检员信息
     * 
     * @param id 巡检员主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteFasIpqcById(Long id)
    {
        return fasIpqcMapper.deleteFasIpqcById(id);
    }

    @Override
    public List<FasIpqc> selectFasIpqcList1(FasIpqc fasIpqc) {
        //根据条件查询出对应的条件
        List<FasIpqc> fasIpqcs = fasIpqcMapper.selectFasIpqcList1(fasIpqc);
//
//        for (FasIpqc i:fasIpqcs) {
//            System.out.println(i.getBuilding_id());
//            String buildingName = fasIpqcMapper.selectFasIpqcBuildingName(i.getBuilding_id());
//
//            i.setManageFirm(buildingName);
//        }
        return fasIpqcs;

    }

    @Override
    public FasIpqc selectFasIpqcxiangxi(String worknumber , Long deptId) {

        FasIpqc fasIpqc = fasIpqcMapper.selectFasIpqcBynumber(worknumber);
//        List list1 = fasIpqcMapper.selectFasIpqcBynumberdept(worknumber);
//        System.out.println("全查为："+fasIpqc);
//        System.out.println("查询的负责区域为："+list1);
//        fasIpqc.setBuilding_name(list1);

        return fasIpqc;
    }

    @Override
    public List<FasIpqc> selectFasIpqcByDeptId(FasIpqc fasIpqc) {
        return fasIpqcMapper.selectFasIpqcByDeptId(fasIpqc);
    }
}
